package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) {
        /*
        use empdb;
        create table user(id int primary key auto_increment,
        username varchar(50),
        password varchar(50),
        nick varchar(50));
        */
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();
        System.out.println("请输入昵称：");
        String nick = sc.nextLine();
        //获取连接
        try ( Connection conn = DBUtils.getConn()){
//            Statement s = conn.createStatement();
//            s.executeUpdate("insert into user values (null ,'"
//                    +username+"','"+password+"','"+nick+"')");
            String sql = "insert into user values(null,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,username);
            ps.setString(2,password);
            ps.setString(3,nick);
            ps.executeUpdate();
            System.out.println("注册成功！");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
